package vn.bum.game.web.base;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CleanupFilter implements Filter {
	@Override
	public void destroy() {
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		BufferedResponseWrapper wrappedResponse = new BufferedResponseWrapper(response);
		chain.doFilter(request, wrappedResponse);
		
		String bufferString = wrappedResponse.getBufferAsString();
		bufferString = bufferString
		.replaceAll("\\s+", " ")
		.trim();
		
//		bufferString = TextExUtil.clearVNChars(bufferString);

		PrintWriter out = response.getWriter();
		out.write(bufferString);
		out.flush();
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
	}
}
